﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yule8xCommon.Applib;

namespace Yule8xWxToolkit.Other
{
    public partial class WxTest : System.Web.UI.Page
    {
        protected string token;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (RequestUtil.GetString("action", maxLen: 16) == "testnews")
                {
                    this.testNews();
                }
                token = WechatUtil.GetToken();
            }
        }
        protected void testNews()
        {
            string text = "<xml><ToUserName><![CDATA[gh_3b83505121ec]]></ToUserName><FromUserName><![CDATA[ou7IyxIe-0-lU4uqV17aDI7EOW08]]></FromUserName><CreateTime>1497690797</CreateTime><MsgType><![CDATA[news]]></MsgType><ArticleCount>1</ArticleCount><Articles><item><Title><![CDATA[合作代理玩棋牌，八星娱乐游戏赚钱两不误]]></Title><Discription><![CDATA[移动互联网时代，棋牌游戏的火爆程度已经风靡各地，而多地方特色游戏棋牌平台“八星游戏”的到来，能让您的家人和朋友在随时随地体验自己喜欢的棋牌游戏。]]></Discription><PicUrl><![CDATA[]]></PicUrl><Url><![CDATA[http://mp.weixin.qq.com/s/tfmfDv_Gz0IJ-BIDs7n76Q]]></Url></item></Articles></xml>";
            Response.ContentType = "application/xml";
            Response.Write(text);
            Response.End();
        }

        protected void btn_submit_Click(object sender, EventArgs e)
        {
            string operate = ddlOperate.SelectedValue;
            string url, content;
            switch (operate)
            {
                case "batchget_material":
                    // 获取素材列表
                    url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=" + WechatUtil.GetToken();
                    content = HttpUtil.HttpPost(url, "{'type':'news','offset':0,'count':20}".Replace("'", "\""));
                    Response.Write(Server.HtmlEncode(content));
                    break;
                case "get_material":
                    string mediaid = tb_value1.Text;
                    url = "https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=" + WechatUtil.GetToken();
                    content = HttpUtil.HttpPost(url, "{'media_id':'" + mediaid + "'}".Replace("'", "\""),"utf-8");
                    Response.Write(Server.HtmlEncode(content));
                    break;
            }
        }
    }
}